package niuke.meituan2021._2021_11_03;

import java.util.Scanner;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/11/03 08:41
 */
public class Three {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            sc.nextLine();
            char[] scs = sc.nextLine().toCharArray();
            int peoN = sc.nextInt();
            sc.nextLine();
            char[] peos = sc.nextLine().toCharArray();
            for (char pc : peos) {
                if (pc == 'M') {
                    int oka = -1;
                    int okb = -1;
                    for (int i = 0; i < scs.length; i++) {
                        if (okb == -1 && scs[i] == '0') {
                            okb = i;
                        } else if (scs[i] == '1') {
                            oka = i;
                            break;
                        }
                    }
                    if (oka != -1) {
                        scs[oka] = '2';
                        System.out.println(oka+1);
                    } else if (okb != -1) {
                        scs[okb] = '1';
                        System.out.println(okb+1);
                    }
                } else {
                    int oka = -1;
                    int okb = -1;
                    for (int i = 0; i < scs.length; i++) {
                        if (okb == -1 && scs[i] == '1') {
                            okb = i;
                        } else if (scs[i] == '0') {
                            oka = i;
                            break;
                        }
                    }
                    if (oka != -1) {
                        scs[oka] = '1';
                        System.out.println(oka+1);
                    } else if (okb != -1) {
                        scs[okb] = '2';
                        System.out.println(okb+1);
                    }
                }
            }
        }

    }
}
